package com.wangzhenyu.learn.test.designPattern

//装饰器模式


@Suppress("UNUSED")
object IDecoratorPattern {

    abstract class Drink {

        var desc: String = ""

        var price: Float = 0.0f

        abstract fun cost(): Float

        abstract fun desc(): String

    }

    abstract class Coffee : Drink() {

        override fun cost(): Float {
            return price
        }

        override fun desc(): String {
            return desc
        }
    }

    class CoffeeA : Coffee() {

        init {
            this.desc = "咖啡一号"
            this.price = 6.0f
        }
    }

    class CoffeeB : Coffee() {

        init {
            this.desc = "咖啡二号"
            this.price = 5.0f
        }

    }

    class CoffeeC : Coffee() {

        init {
            this.desc = "咖啡三号"
            this.price = 9.0f
        }

    }

    abstract class Decorator(private val drink: Drink) : Drink() {

        override fun cost(): Float {
            return price + drink.cost()
        }

        override fun desc(): String {
            return desc + "  " + drink.desc()
        }
    }

    class Chocolate(drink: Drink) : Decorator(drink) {
        init {
            this.desc = "巧克力"
            this.price = 1.0f
        }
    }

    class Juice(drink: Drink) : Decorator(drink) {
        init {
            this.desc = "果汁"
            this.price = 4.0f
        }
    }

    class Milk(drink: Drink) : Decorator(drink) {
        init {
            this.desc = "牛奶"
            this.price = 3.0f
        }
    }
}